const { connection } = require('../../model/database')

module.exports = (req, res) => {
    var num = []
    // 查询文章
    connection.query('select count(id) num from article;', async (error1, reslut1) => {
        if (error1) {
            console.log('查询失败');
            return
        }
        var obj = {
            name: '文章',
            num:reslut1[0].num
        }
        num.push(obj)
        // 查询分类
        connection.query('select count(id) num from class;', async (error2, reslut2) => {
            if (error2) {
                console.log('查询失败');
            }
            var obj = {
                name: '分类',
                num:reslut2[0].num
            }
            num.push(obj)

        })
             // 查询评论
             connection.query('select count(id) num from comments;', async (error3, reslut3) => {
                if (error3) {
                    console.log('查询失败');
                }
                var obj = {
                    name: '评论',
                    num:reslut3[0].num
                }
                num.push(obj)
                res.send(num)
            })

    })

    
   
}